<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .moren{
            background-color: white;
        }
        .success{
            background-color: greenyellow;
        }
        .warning{
            background-color: rgb(252, 198, 99);
        }
    </style>
</head>
<body>
    <div id="app">
        <btn :class-name="btnClass">{{content}}</btn>
        <button v-for='(item,index) in list' @click="click3(item.title)" :class="[item.cla]">{{item.title}}</button>
    </div>
    <template id="btn">
        <div>
            <button :class=[className]><slot></slot></button>
        </div>
    </template>
    <script src="../vue.js"></script>
    <script>
        let btn={
            template:'#btn',
            props: ['className'],
        }
        new Vue({
            el:'#app',
            data () {
                return {
                    content:'默认',
                    list:[
                        {title:'默认',cla:'moren'},
                        {title:'成功',cla:'success'},
                        {title:'警告',cla:'warning'},
                    ],
                    btnClass:'',
                }
            },
            components: {
                btn,
            },
            methods: {
                click3(ti){
                    if(ti=="默认"){
                        this.content=ti;
                        this.btnClass='moren';
                    }
                    else if(ti=="成功"){
                        this.content=ti;
                        this.btnClass='success';
                    }
                    else if(ti="警告"){
                        this.content=ti;
                        this.btnClass='warning';
                    }
                }
            }
        })
    </script>
</body>
</html>